<?php
/**
 * 广告管理插件,可以管理banner广告,文字广告,支持分类,参考多个广告插件来开发.
 * date:2018-06-30
 * author: yoby
 */
require_once(dirname(__FILE__).'/config.php');
require_once(DEDEINC.'/datalistcp.class.php');
require_once(DEDEINC.'/common.func.php');
setcookie('ENV_GOBACK_URL',$dedeNowurl,time()+3600,'/');

$dopost = (empty($dopost))?"display":$dopost;

if("del" == $dopost){
    $sql = "delete from #@__yoby_adtype where id=$id";
    $dsql->ExecNoneQuery($sql);
    $sql1 = "delete from #@__yoby_adlist where tid=$id";
    $dsql->ExecNoneQuery($sql1);
    $json = array(
        "code"=>200
    );
    exit(json_encode($json));

}else if("post" == $dopost){
  $typename =   trim($typename);
    if(empty($ids)){
        $sql = "insert into #@__yoby_adtype (typename) VALUES ('$typename')";
        $dsql->ExecNoneQuery($sql);
        $id = $dsql->GetLastID();

    }else{

        $sql = "update #@__yoby_adtype set typename='$typename' where id=$ids";
        $rs = $dsql->ExecNoneQuery($sql);

    }
    if($id>0 || ($rs==true)){
        $json = array(
            "code"=>200
        );
        exit(json_encode($json));
    }else{
        $json = array(
            "code"=>400
        );
        exit(json_encode($json));
    }


}else if("getrs"==$dopost){
    $row = $dsql->GetOne("SELECT * FROM #@__yoby_adtype WHERE id= $id");
    $json = array(
        "code"=>400 ,
        "list"=>$row
    );
    exit(json_encode($json));
}

else if("display"==$dopost){
    $where = "";
    $sql = "select * from #@__yoby_adtype where 1=1 $where order by id desc";
    $dl = new DataListCP();
    $dl->pageSize = 10;
    $dl->SetTemplate(DEDEADMIN."/templets/yoby_ad_main.htm");
    $dl->SetSource($sql);
    $dl->Display();
}

